package com.entfrm.biz.it.manager;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.entfrm.biz.it.entity.RepairEmail;
import com.entfrm.biz.it.service.RepairEmailService;
import com.entfrm.core.base.constant.CommonConstants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;

/**
 * <h3>entfrm</h3>
 * <p>报修邮箱</p>
 *
 * @author : kyc
 * @date : 2020-08-17 09:50
 **/
@Component
public class RepairEmailManager {

    @Autowired
    private RepairEmailService repairEmailService;

    /**
     * 使用报修邮箱
     */
    public void useRepairEmail(Integer id) {
        RepairEmail repairEmailOld = repairEmailService.getOne(new QueryWrapper<RepairEmail>().lambda().eq(RepairEmail::getIsUse, CommonConstants.Status.YES));
        if (repairEmailOld!=null){
            repairEmailOld.setIsUse(CommonConstants.Status.NO);
            repairEmailService.updateById(repairEmailOld);
        }
        RepairEmail repairEmail = new RepairEmail();
        repairEmail.setId(id).setIsUse(CommonConstants.Status.YES);
        repairEmailService.updateById(repairEmail);
    }
}
